home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / controls / MenuBar.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  37.5 KB  |  1,155 lines

  1. package mx.controls
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.Event;
  5.    import flash.events.FocusEvent;
  6.    import flash.events.KeyboardEvent;
  7.    import flash.events.MouseEvent;
  8.    import flash.geom.Point;
  9.    import flash.geom.Rectangle;
  10.    import flash.ui.Keyboard;
  11.    import flash.xml.XMLNode;
  12.    import mx.collections.ArrayCollection;
  13.    import mx.collections.ICollectionView;
  14.    import mx.collections.IViewCursor;
  15.    import mx.collections.XMLListCollection;
  16.    import mx.collections.errors.ItemPendingError;
  17.    import mx.containers.ApplicationControlBar;
  18.    import mx.controls.menuClasses.IMenuBarItemRenderer;
  19.    import mx.controls.menuClasses.IMenuDataDescriptor;
  20.    import mx.controls.menuClasses.MenuBarItem;
  21.    import mx.controls.treeClasses.DefaultDataDescriptor;
  22.    import mx.core.ClassFactory;
  23.    import mx.core.EventPriority;
  24.    import mx.core.FlexVersion;
  25.    import mx.core.IFactory;
  26.    import mx.core.IFlexDisplayObject;
  27.    import mx.core.IUIComponent;
  28.    import mx.core.UIComponent;
  29.    import mx.core.UIComponentGlobals;
  30.    import mx.core.mx_internal;
  31.    import mx.events.CollectionEvent;
  32.    import mx.events.CollectionEventKind;
  33.    import mx.events.FlexEvent;
  34.    import mx.events.InterManagerRequest;
  35.    import mx.events.MenuEvent;
  36.    import mx.managers.IFocusManagerComponent;
  37.    import mx.managers.ISystemManager;
  38.    import mx.styles.CSSStyleDeclaration;
  39.    import mx.styles.ISimpleStyleClient;
  40.    import mx.styles.StyleManager;
  41.    import mx.styles.StyleProxy;
  42.    
  43.    use namespace mx_internal;
  44.    
  45.    public class MenuBar extends UIComponent implements IFocusManagerComponent
  46.    {
  47.       mx_internal static var createAccessibilityImplementation:Function;
  48.       
  49.       mx_internal static const VERSION:String = "3.2.0.3958";
  50.       
  51.       private static const MARGIN_WIDTH:int = 10;
  52.       
  53.       private static var _menuBarItemStyleFilters:Object = null;
  54.       
  55.       private var dataProviderChanged:Boolean = false;
  56.       
  57.       public var menus:Array;
  58.       
  59.       private var _labelField:String = "label";
  60.       
  61.       private var menuBarItemRendererChanged:Boolean = false;
  62.       
  63.       private var _menuBarItemRenderer:IFactory;
  64.       
  65.       private var openMenuIndex:int = -1;
  66.       
  67.       public var menuBarItems:Array;
  68.       
  69.       private var _iconField:String = "icon";
  70.       
  71.       private var background:IFlexDisplayObject;
  72.       
  73.       mx_internal var showRootChanged:Boolean = false;
  74.       
  75.       private var inKeyDown:Boolean = false;
  76.       
  77.       private var isInsideACB:Boolean = false;
  78.       
  79.       mx_internal var _hasRoot:Boolean = false;
  80.       
  81.       mx_internal var _showRoot:Boolean = true;
  82.       
  83.       private var supposedToLoseFocus:Boolean = false;
  84.       
  85.       mx_internal var _dataDescriptor:IMenuDataDescriptor;
  86.       
  87.       mx_internal var _rootModel:ICollectionView;
  88.       
  89.       public var labelFunction:Function;
  90.       
  91.       private var iconFieldChanged:Boolean = false;
  92.       
  93.       private var isDown:Boolean;
  94.       
  95.       public function MenuBar()
  96.       {
  97.          mx_internal::_dataDescriptor = new DefaultDataDescriptor();
  98.          menuBarItems = [];
  99.          menus = [];
  100.          super();
  101.          menuBarItemRenderer = new ClassFactory(MenuBarItem);
  102.          tabChildren = false;
  103.       }
  104.       
  105.       [Bindable("iconFieldChanged")]
  106.       public function get iconField() : String
  107.       {
  108.          return _iconField;
  109.       }
  110.       
  111.       override public function set enabled(param1:Boolean) : void
  112.       {
  113.          var _loc2_:int = 0;
  114.          var _loc3_:int = 0;
  115.          super.enabled = param1;
  116.          if(menuBarItems)
  117.          {
  118.             _loc2_ = int(menuBarItems.length);
  119.             _loc3_ = 0;
  120.             while(_loc3_ < _loc2_)
  121.             {
  122.                menuBarItems[_loc3_].enabled = param1;
  123.                _loc3_++;
  124.             }
  125.          }
  126.       }
  127.       
  128.       public function get showRoot() : Boolean
  129.       {
  130.          return mx_internal::_showRoot;
  131.       }
  132.       
  133.       override public function set showInAutomationHierarchy(param1:Boolean) : void
  134.       {
  135.       }
  136.       
  137.       private function removeAll() : void
  138.       {
  139.          var _loc1_:IMenuBarItemRenderer = null;
  140.          if(dataProviderChanged)
  141.          {
  142.             commitProperties();
  143.          }
  144.          while(menuBarItems.length > 0)
  145.          {
  146.             _loc1_ = menuBarItems[0];
  147.             removeChild(DisplayObject(_loc1_));
  148.             menuBarItems.splice(0,1);
  149.          }
  150.          menus = [];
  151.          invalidateSize();
  152.          invalidateDisplayList();
  153.       }
  154.       
  155.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  156.       {
  157.          var _loc9_:IMenuBarItemRenderer = null;
  158.          super.updateDisplayList(param1,param2);
  159.          var _loc3_:Number = MARGIN_WIDTH;
  160.          var _loc4_:Number = 0;
  161.          var _loc5_:int = int(menuBarItems.length);
  162.          var _loc6_:Boolean = false;
  163.          var _loc7_:Boolean = param1 == 0 || param2 == 0;
  164.          var _loc8_:int = 0;
  165.          while(_loc8_ < _loc5_)
  166.          {
  167.             _loc9_ = menuBarItems[_loc8_];
  168.             _loc9_.setActualSize(_loc9_.getExplicitOrMeasuredWidth(),param2);
  169.             _loc9_.visible = !_loc7_;
  170.             _loc3_ = _loc9_.x = _loc3_ + _loc4_;
  171.             _loc4_ = Number(_loc9_.width);
  172.             if(!_loc7_ && (_loc9_.getExplicitOrMeasuredHeight() > param2 || _loc3_ + _loc4_ > param1))
  173.             {
  174.                _loc6_ = true;
  175.             }
  176.             _loc8_++;
  177.          }
  178.          if(background)
  179.          {
  180.             background.setActualSize(param1,param2);
  181.             background.visible = !_loc7_;
  182.          }
  183.          scrollRect = _loc6_ ? new Rectangle(0,0,param1,param2) : null;
  184.       }
  185.       
  186.       override public function get baselinePosition() : Number
  187.       {
  188.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  189.          {
  190.             return super.baselinePosition;
  191.          }
  192.          if(!mx_internal::validateBaselinePosition())
  193.          {
  194.             return NaN;
  195.          }
  196.          if(menuBarItems.length == 0)
  197.          {
  198.             return super.baselinePosition;
  199.          }
  200.          var _loc1_:IUIComponent = menuBarItems[0] as IUIComponent;
  201.          if(!_loc1_)
  202.          {
  203.             return super.baselinePosition;
  204.          }
  205.          validateNow();
  206.          return _loc1_.y + _loc1_.baselinePosition;
  207.       }
  208.       
  209.       protected function get menuBarItemStyleFilters() : Object
  210.       {
  211.          return _menuBarItemStyleFilters;
  212.       }
  213.       
  214.       public function set iconField(param1:String) : void
  215.       {
  216.          if(_iconField != param1)
  217.          {
  218.             iconFieldChanged = true;
  219.             _iconField = param1;
  220.             invalidateProperties();
  221.             dispatchEvent(new Event("iconFieldChanged"));
  222.          }
  223.       }
  224.       
  225.       public function set menuBarItemRenderer(param1:IFactory) : void
  226.       {
  227.          if(_menuBarItemRenderer != param1)
  228.          {
  229.             _menuBarItemRenderer = param1;
  230.             menuBarItemRendererChanged = true;
  231.             invalidateProperties();
  232.             dispatchEvent(new Event("menuBarItemRendererChanged"));
  233.          }
  234.       }
  235.       
  236.       public function get hasRoot() : Boolean
  237.       {
  238.          return mx_internal::_hasRoot;
  239.       }
  240.       
  241.       override protected function initializeAccessibility() : void
  242.       {
  243.          if(MenuBar.mx_internal::createAccessibilityImplementation != null)
  244.          {
  245.             MenuBar.mx_internal::createAccessibilityImplementation(this);
  246.          }
  247.       }
  248.       
  249.       public function itemToIcon(param1:Object) : Class
  250.       {
  251.          var iconClass:Class = null;
  252.          var icon:* = undefined;
  253.          var data:Object = param1;
  254.          if(data == null)
  255.          {
  256.             return null;
  257.          }
  258.          if(data is XML)
  259.          {
  260.             try
  261.             {
  262.                if(data[iconField].length() != 0)
  263.                {
  264.                   icon = String(data[iconField]);
  265.                   if(icon != null)
  266.                   {
  267.                      iconClass = Class(systemManager.getDefinitionByName(icon));
  268.                      if(iconClass)
  269.                      {
  270.                         return iconClass;
  271.                      }
  272.                      return document[icon];
  273.                   }
  274.                }
  275.             }
  276.             catch(e:Error)
  277.             {
  278.             }
  279.          }
  280.          else if(data is Object)
  281.          {
  282.             try
  283.             {
  284.                if(data[iconField] != null)
  285.                {
  286.                   if(data[iconField] is Class)
  287.                   {
  288.                      return data[iconField];
  289.                   }
  290.                   if(data[iconField] is String)
  291.                   {
  292.                      iconClass = Class(systemManager.getDefinitionByName(data[iconField]));
  293.                      if(iconClass)
  294.                      {
  295.                         return iconClass;
  296.                      }
  297.                      return document[data[iconField]];
  298.                   }
  299.                }
  300.             }
  301.             catch(e:Error)
  302.             {
  303.             }
  304.          }
  305.          return null;
  306.       }
  307.       
  308.       private function addMenuAt(param1:int, param2:Object, param3:Object = null) : void
  309.       {
  310.          var _loc4_:Menu = null;
  311.          var _loc5_:Object = null;
  312.          if(!dataProvider)
  313.          {
  314.             dataProvider = {};
  315.          }
  316.          var _loc6_:Object = param2;
  317.          insertMenuBarItem(param1,_loc5_);
  318.       }
  319.       
  320.       override protected function createChildren() : void
  321.       {
  322.          super.createChildren();
  323.          var _loc1_:Object = parent;
  324.          while(_loc1_)
  325.          {
  326.             if(_loc1_ is ApplicationControlBar)
  327.             {
  328.                isInsideACB = true;
  329.                break;
  330.             }
  331.             _loc1_ = _loc1_.parent;
  332.          }
  333.          updateBackground();
  334.       }
  335.       
  336.       override protected function focusOutHandler(param1:FocusEvent) : void
  337.       {
  338.          super.focusOutHandler(param1);
  339.          if(supposedToLoseFocus)
  340.          {
  341.             getMenuAt(openMenuIndex).hide();
  342.          }
  343.          supposedToLoseFocus = false;
  344.       }
  345.       
  346.       public function itemToLabel(param1:Object) : String
  347.       {
  348.          var data:Object = param1;
  349.          if(data == null)
  350.          {
  351.             return " ";
  352.          }
  353.          if(labelFunction != null)
  354.          {
  355.             return labelFunction(data);
  356.          }
  357.          if(data is XML)
  358.          {
  359.             try
  360.             {
  361.                if(data[labelField].length() != 0)
  362.                {
  363.                   data = data[labelField];
  364.                }
  365.             }
  366.             catch(e:Error)
  367.             {
  368.             }
  369.          }
  370.          else if(data is Object)
  371.          {
  372.             try
  373.             {
  374.                if(data[labelField] != null)
  375.                {
  376.                   data = data[labelField];
  377.                }
  378.             }
  379.             catch(e:Error)
  380.             {
  381.             }
  382.          }
  383.          else if(data is String)
  384.          {
  385.             return String(data);
  386.          }
  387.          try
  388.          {
  389.             return data.toString();
  390.          }
  391.          catch(e:Error)
  392.          {
  393.          }
  394.          return " ";
  395.       }
  396.       
  397.       private function mouseOutHandler(param1:MouseEvent) : void
  398.       {
  399.          var _loc5_:MenuEvent = null;
  400.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  401.          var _loc3_:int = _loc2_.menuBarItemIndex;
  402.          var _loc4_:Menu = getMenuAt(_loc3_);
  403.          if(Boolean(_loc2_.enabled) && openMenuIndex != _loc3_)
  404.          {
  405.             menuBarItems[_loc3_].menuBarItemState = "itemUpSkin";
  406.          }
  407.          if(Boolean(_loc2_.data) && _loc4_.dataDescriptor.getType(_loc2_.data) != "separator")
  408.          {
  409.             _loc5_ = new MenuEvent(MenuEvent.ITEM_ROLL_OUT);
  410.             _loc5_.index = _loc3_;
  411.             _loc5_.menuBar = this;
  412.             _loc5_.label = itemToLabel(_loc2_.data);
  413.             _loc5_.item = _loc2_.data;
  414.             _loc5_.itemRenderer = _loc2_;
  415.             dispatchEvent(_loc5_);
  416.          }
  417.       }
  418.       
  419.       private function collectionChangeHandler(param1:Event) : void
  420.       {
  421.          var _loc2_:CollectionEvent = null;
  422.          if(param1 is CollectionEvent)
  423.          {
  424.             _loc2_ = CollectionEvent(param1);
  425.             if(_loc2_.kind == CollectionEventKind.ADD)
  426.             {
  427.                dataProviderChanged = true;
  428.                invalidateProperties();
  429.             }
  430.             else if(_loc2_.kind == CollectionEventKind.REMOVE)
  431.             {
  432.                dataProviderChanged = true;
  433.                invalidateProperties();
  434.             }
  435.             else if(_loc2_.kind == CollectionEventKind.REFRESH)
  436.             {
  437.                dataProviderChanged = true;
  438.                dataProvider = dataProvider;
  439.                invalidateProperties();
  440.                invalidateSize();
  441.             }
  442.             else if(_loc2_.kind == CollectionEventKind.RESET)
  443.             {
  444.                dataProviderChanged = true;
  445.                invalidateProperties();
  446.                invalidateSize();
  447.             }
  448.             else if(_loc2_.kind == CollectionEventKind.UPDATE)
  449.             {
  450.                if(openMenuIndex == -1)
  451.                {
  452.                   dataProviderChanged = true;
  453.                   invalidateProperties();
  454.                }
  455.             }
  456.          }
  457.          invalidateDisplayList();
  458.       }
  459.       
  460.       override public function notifyStyleChangeInChildren(param1:String, param2:Boolean) : void
  461.       {
  462.          super.notifyStyleChangeInChildren(param1,param2);
  463.          var _loc3_:int = int(menuBarItems.length);
  464.          var _loc4_:int = 0;
  465.          while(_loc4_ < _loc3_)
  466.          {
  467.             getMenuAt(_loc4_).notifyStyleChangeInChildren(param1,param2);
  468.             _loc4_++;
  469.          }
  470.       }
  471.       
  472.       private function mouseUpHandler(param1:MouseEvent) : void
  473.       {
  474.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  475.          var _loc3_:int = _loc2_.menuBarItemIndex;
  476.          if(Boolean(_loc2_.enabled) && !isDown)
  477.          {
  478.             getMenuAt(_loc3_).mx_internal::hideAllMenus();
  479.             _loc2_.menuBarItemState = "itemOverSkin";
  480.          }
  481.       }
  482.       
  483.       private function mouseDownHandler(param1:MouseEvent) : void
  484.       {
  485.          var _loc5_:ICollectionView = null;
  486.          var _loc6_:MenuEvent = null;
  487.          var _loc7_:MenuEvent = null;
  488.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  489.          var _loc3_:int = _loc2_.menuBarItemIndex;
  490.          var _loc4_:Menu = getMenuAt(_loc3_);
  491.          if(_loc2_.enabled)
  492.          {
  493.             _loc2_.menuBarItemState = "itemDownSkin";
  494.             if(!isDown)
  495.             {
  496.                _loc4_.mx_internal::supposedToLoseFocus = true;
  497.                _loc5_ = ICollectionView(_loc4_.dataProvider);
  498.                if(_loc4_.dataDescriptor.isBranch(_loc2_.data,_loc2_.data) && _loc4_.dataDescriptor.hasChildren(_loc2_.data,_loc2_.data))
  499.                {
  500.                   showMenu(_loc3_);
  501.                }
  502.                else if(_loc4_)
  503.                {
  504.                   selectedIndex = _loc3_;
  505.                   _loc6_ = new MenuEvent(MenuEvent.MENU_SHOW);
  506.                   _loc6_.menuBar = this;
  507.                   _loc6_.menu = _loc4_;
  508.                   dispatchEvent(_loc6_);
  509.                }
  510.                isDown = true;
  511.             }
  512.             else
  513.             {
  514.                isDown = false;
  515.             }
  516.             if(_loc4_.dataDescriptor.getType(_loc2_.data) != "separator")
  517.             {
  518.                _loc7_ = new MenuEvent(MenuEvent.CHANGE);
  519.                _loc7_.index = _loc3_;
  520.                _loc7_.menuBar = this;
  521.                _loc7_.label = itemToLabel(_loc2_.data);
  522.                _loc7_.item = _loc2_.data;
  523.                _loc7_.itemRenderer = _loc2_;
  524.                dispatchEvent(_loc7_);
  525.             }
  526.          }
  527.       }
  528.       
  529.       public function get dataDescriptor() : IMenuDataDescriptor
  530.       {
  531.          return IMenuDataDescriptor(mx_internal::_dataDescriptor);
  532.       }
  533.       
  534.       [Bindable("collectionChange")]
  535.       public function get dataProvider() : Object
  536.       {
  537.          if(mx_internal::_rootModel)
  538.          {
  539.             return mx_internal::_rootModel;
  540.          }
  541.          return null;
  542.       }
  543.       
  544.       private function showMenu(param1:Number) : void
  545.       {
  546.          var _loc6_:Rectangle = null;
  547.          var _loc8_:InterManagerRequest = null;
  548.          selectedIndex = param1;
  549.          var _loc2_:IMenuBarItemRenderer = menuBarItems[param1];
  550.          var _loc3_:Menu = getMenuAt(param1);
  551.          var _loc4_:ISystemManager = systemManager.topLevelSystemManager;
  552.          var _loc5_:DisplayObject = _loc4_.getSandboxRoot();
  553.          if(_loc4_ != _loc5_)
  554.          {
  555.             _loc8_ = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST,false,false,"getVisibleApplicationRect");
  556.             _loc5_.dispatchEvent(_loc8_);
  557.             _loc6_ = Rectangle(_loc8_.value);
  558.          }
  559.          else
  560.          {
  561.             _loc6_ = _loc4_.getVisibleApplicationRect();
  562.          }
  563.          UIComponentGlobals.mx_internal::layoutManager.validateClient(_loc3_,true);
  564.          var _loc7_:Point = new Point(0,0);
  565.          _loc7_ = DisplayObject(_loc2_).localToGlobal(_loc7_);
  566.          if(_loc7_.y + _loc2_.height + 1 + _loc3_.getExplicitOrMeasuredHeight() > _loc6_.height + _loc6_.y)
  567.          {
  568.             _loc7_.y -= _loc3_.getExplicitOrMeasuredHeight();
  569.          }
  570.          else
  571.          {
  572.             _loc7_.y += _loc2_.height + 1;
  573.          }
  574.          if(_loc7_.x + _loc3_.getExplicitOrMeasuredWidth() > _loc6_.width + _loc6_.x)
  575.          {
  576.             _loc7_.x = _loc6_.x + _loc6_.width - _loc3_.getExplicitOrMeasuredWidth();
  577.          }
  578.          _loc7_ = _loc5_.globalToLocal(_loc7_);
  579.          if(isInsideACB)
  580.          {
  581.             _loc7_.y += 2;
  582.          }
  583.          _loc3_.show(_loc7_.x,_loc7_.y);
  584.       }
  585.       
  586.       [Bindable("menuBarItemRendererChanged")]
  587.       public function get menuBarItemRenderer() : IFactory
  588.       {
  589.          return _menuBarItemRenderer;
  590.       }
  591.       
  592.       public function getMenuAt(param1:int) : Menu
  593.       {
  594.          var _loc5_:Object = null;
  595.          var _loc6_:CSSStyleDeclaration = null;
  596.          if(dataProviderChanged)
  597.          {
  598.             commitProperties();
  599.          }
  600.          var _loc2_:IMenuBarItemRenderer = menuBarItems[param1];
  601.          var _loc3_:Object = _loc2_.data;
  602.          var _loc4_:Menu = menus[param1];
  603.          if(_loc4_ == null)
  604.          {
  605.             _loc4_ = new Menu();
  606.             _loc4_.showRoot = false;
  607.             if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  608.             {
  609.                _loc4_.styleName = this;
  610.             }
  611.             _loc5_ = getStyle("menuStyleName");
  612.             if(_loc5_)
  613.             {
  614.                if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  615.                {
  616.                   _loc6_ = StyleManager.getStyleDeclaration("." + _loc5_);
  617.                   if(_loc6_)
  618.                   {
  619.                      _loc4_.styleDeclaration = _loc6_;
  620.                   }
  621.                }
  622.                else
  623.                {
  624.                   _loc4_.styleName = _loc5_;
  625.                }
  626.             }
  627.             _loc4_.mx_internal::sourceMenuBar = this;
  628.             _loc4_.owner = this;
  629.             _loc4_.addEventListener("menuHide",eventHandler);
  630.             _loc4_.addEventListener("itemRollOver",eventHandler);
  631.             _loc4_.addEventListener("itemRollOut",eventHandler);
  632.             _loc4_.addEventListener("menuShow",eventHandler);
  633.             _loc4_.addEventListener("itemClick",eventHandler);
  634.             _loc4_.addEventListener("change",eventHandler);
  635.             _loc4_.iconField = _iconField;
  636.             _loc4_.labelField = _labelField;
  637.             _loc4_.labelFunction = labelFunction;
  638.             _loc4_.dataDescriptor = mx_internal::_dataDescriptor;
  639.             _loc4_.invalidateSize();
  640.             menus[param1] = _loc4_;
  641.             _loc4_.mx_internal::sourceMenuBarItem = _loc2_;
  642.             Menu.popUpMenu(_loc4_,this,_loc3_);
  643.          }
  644.          return _loc4_;
  645.       }
  646.       
  647.       public function set labelField(param1:String) : void
  648.       {
  649.          if(_labelField != param1)
  650.          {
  651.             _labelField = param1;
  652.             dispatchEvent(new Event("labelFieldChanged"));
  653.          }
  654.       }
  655.       
  656.       override protected function commitProperties() : void
  657.       {
  658.          var i:int = 0;
  659.          var cursor:IViewCursor = null;
  660.          var tmpCollection:ICollectionView = null;
  661.          var rootItem:* = undefined;
  662.          if(mx_internal::showRootChanged)
  663.          {
  664.             if(!mx_internal::_hasRoot)
  665.             {
  666.                mx_internal::showRootChanged = false;
  667.             }
  668.          }
  669.          if(dataProviderChanged || mx_internal::showRootChanged)
  670.          {
  671.             dataProviderChanged = false;
  672.             mx_internal::showRootChanged = false;
  673.             if(mx_internal::_rootModel && !mx_internal::_showRoot && mx_internal::_hasRoot)
  674.             {
  675.                rootItem = mx_internal::_rootModel.createCursor().current;
  676.                if(rootItem != null && mx_internal::_dataDescriptor.isBranch(rootItem,mx_internal::_rootModel) && mx_internal::_dataDescriptor.hasChildren(rootItem,mx_internal::_rootModel))
  677.                {
  678.                   tmpCollection = mx_internal::_dataDescriptor.getChildren(rootItem,mx_internal::_rootModel);
  679.                }
  680.             }
  681.             removeAll();
  682.             if(mx_internal::_rootModel)
  683.             {
  684.                if(!tmpCollection)
  685.                {
  686.                   tmpCollection = mx_internal::_rootModel;
  687.                }
  688.                tmpCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,EventPriority.DEFAULT_HANDLER,true);
  689.                if(tmpCollection.length > 0)
  690.                {
  691.                   cursor = tmpCollection.createCursor();
  692.                   i = 0;
  693.                   while(!cursor.afterLast)
  694.                   {
  695.                      try
  696.                      {
  697.                         insertMenuBarItem(i,cursor.current);
  698.                      }
  699.                      catch(e:ItemPendingError)
  700.                      {
  701.                      }
  702.                      cursor.moveNext();
  703.                      i++;
  704.                   }
  705.                }
  706.             }
  707.          }
  708.          if(iconFieldChanged || menuBarItemRendererChanged)
  709.          {
  710.             iconFieldChanged = false;
  711.             menuBarItemRendererChanged = false;
  712.             removeAll();
  713.             if(mx_internal::_rootModel)
  714.             {
  715.                if(!tmpCollection)
  716.                {
  717.                   tmpCollection = mx_internal::_rootModel;
  718.                }
  719.                if(tmpCollection.length > 0)
  720.                {
  721.                   cursor = tmpCollection.createCursor();
  722.                   i = 0;
  723.                   while(!cursor.afterLast)
  724.                   {
  725.                      try
  726.                      {
  727.                         insertMenuBarItem(i,cursor.current);
  728.                      }
  729.                      catch(e:ItemPendingError)
  730.                      {
  731.                      }
  732.                      cursor.moveNext();
  733.                      i++;
  734.                   }
  735.                }
  736.             }
  737.          }
  738.          super.commitProperties();
  739.       }
  740.       
  741.       override public function styleChanged(param1:String) : void
  742.       {
  743.          var _loc2_:int = 0;
  744.          var _loc4_:String = null;
  745.          var _loc5_:Menu = null;
  746.          var _loc6_:CSSStyleDeclaration = null;
  747.          super.styleChanged(param1);
  748.          var _loc3_:int = int(menuBarItems.length);
  749.          _loc2_ = 0;
  750.          while(_loc2_ < _loc3_)
  751.          {
  752.             getMenuAt(_loc2_).styleChanged(param1);
  753.             _loc2_++;
  754.          }
  755.          if(!param1 || param1 == "" || param1 == "backgroundSkin")
  756.          {
  757.             updateBackground();
  758.          }
  759.          if(param1 == null || param1 == "styleName" || param1 == "menuStyleName")
  760.          {
  761.             _loc4_ = getStyle("menuStyleName");
  762.             if(_loc4_)
  763.             {
  764.                if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  765.                {
  766.                   _loc6_ = StyleManager.getStyleDeclaration("." + _loc4_);
  767.                   if(_loc6_)
  768.                   {
  769.                      _loc2_ = 0;
  770.                      while(_loc2_ < menus.length)
  771.                      {
  772.                         _loc5_ = menus[_loc2_];
  773.                         _loc5_.styleDeclaration = _loc6_;
  774.                         _loc5_.regenerateStyleCache(true);
  775.                         _loc2_++;
  776.                      }
  777.                   }
  778.                }
  779.                else
  780.                {
  781.                   _loc2_ = 0;
  782.                   while(_loc2_ < menus.length)
  783.                   {
  784.                      _loc5_ = menus[_loc2_];
  785.                      _loc5_.styleName = _loc4_;
  786.                      _loc2_++;
  787.                   }
  788.                }
  789.             }
  790.          }
  791.       }
  792.       
  793.       private function removeMenuBarItemAt(param1:int) : void
  794.       {
  795.          if(dataProviderChanged)
  796.          {
  797.             commitProperties();
  798.          }
  799.          var _loc2_:IMenuBarItemRenderer = menuBarItems[param1];
  800.          if(_loc2_)
  801.          {
  802.             removeChild(DisplayObject(_loc2_));
  803.             menuBarItems.splice(param1,1);
  804.             invalidateSize();
  805.             invalidateDisplayList();
  806.          }
  807.       }
  808.       
  809.       protected function updateBackground() : void
  810.       {
  811.          var _loc1_:Class = null;
  812.          if(isInsideACB)
  813.          {
  814.             setStyle("translucent",true);
  815.          }
  816.          else
  817.          {
  818.             if(background)
  819.             {
  820.                removeChild(DisplayObject(background));
  821.                background = null;
  822.             }
  823.             _loc1_ = getStyle("backgroundSkin");
  824.             background = new _loc1_();
  825.             if(background is ISimpleStyleClient)
  826.             {
  827.                ISimpleStyleClient(background).styleName = this;
  828.             }
  829.             addChildAt(DisplayObject(background),0);
  830.          }
  831.       }
  832.       
  833.       override protected function measure() : void
  834.       {
  835.          super.measure();
  836.          var _loc1_:int = int(menuBarItems.length);
  837.          measuredWidth = 0;
  838.          measuredHeight = DEFAULT_MEASURED_MIN_HEIGHT;
  839.          var _loc2_:int = 0;
  840.          while(_loc2_ < _loc1_)
  841.          {
  842.             measuredWidth += menuBarItems[_loc2_].getExplicitOrMeasuredWidth();
  843.             measuredHeight = Math.max(measuredHeight,menuBarItems[_loc2_].getExplicitOrMeasuredHeight());
  844.             _loc2_++;
  845.          }
  846.          if(_loc1_ > 0)
  847.          {
  848.             measuredWidth += 2 * MARGIN_WIDTH;
  849.          }
  850.          else
  851.          {
  852.             measuredWidth = DEFAULT_MEASURED_MIN_WIDTH;
  853.          }
  854.          measuredMinWidth = measuredWidth;
  855.          measuredMinHeight = measuredHeight;
  856.       }
  857.       
  858.       override protected function keyDownHandler(param1:KeyboardEvent) : void
  859.       {
  860.          var _loc3_:int = 0;
  861.          var _loc4_:Boolean = false;
  862.          var _loc5_:int = 0;
  863.          var _loc6_:Menu = null;
  864.          var _loc7_:ICollectionView = null;
  865.          var _loc8_:IMenuBarItemRenderer = null;
  866.          var _loc2_:int = int(menuBarItems.length);
  867.          if(param1.keyCode == Keyboard.RIGHT || param1.keyCode == Keyboard.LEFT)
  868.          {
  869.             inKeyDown = true;
  870.             _loc3_ = openMenuIndex;
  871.             _loc4_ = false;
  872.             _loc5_ = 0;
  873.             while(!_loc4_ && _loc5_ < _loc2_)
  874.             {
  875.                _loc5_++;
  876.                _loc3_ = param1.keyCode == Keyboard.RIGHT ? _loc3_ + 1 : _loc3_ - 1;
  877.                if(_loc3_ >= _loc2_)
  878.                {
  879.                   _loc3_ = 0;
  880.                }
  881.                else if(_loc3_ < 0)
  882.                {
  883.                   _loc3_ = _loc2_ - 1;
  884.                }
  885.                if(menuBarItems[_loc3_].enabled)
  886.                {
  887.                   _loc4_ = true;
  888.                }
  889.             }
  890.             if(_loc5_ <= _loc2_ && _loc4_)
  891.             {
  892.                menuBarItems[_loc3_].dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
  893.             }
  894.             param1.stopPropagation();
  895.          }
  896.          if(param1.keyCode == Keyboard.DOWN)
  897.          {
  898.             if(openMenuIndex != -1)
  899.             {
  900.                _loc6_ = getMenuAt(openMenuIndex);
  901.                _loc6_.selectedIndex = 0;
  902.                supposedToLoseFocus = true;
  903.                _loc7_ = ICollectionView(_loc6_.dataProvider);
  904.                _loc8_ = _loc6_.mx_internal::sourceMenuBarItem;
  905.                if(_loc6_.dataDescriptor.isBranch(_loc8_.data,_loc8_.data) && _loc6_.dataDescriptor.hasChildren(_loc8_.data,_loc8_.data))
  906.                {
  907.                   _loc6_.setFocus();
  908.                }
  909.             }
  910.             param1.stopPropagation();
  911.          }
  912.          if(param1.keyCode == Keyboard.ENTER || param1.keyCode == Keyboard.ESCAPE)
  913.          {
  914.             if(openMenuIndex != -1)
  915.             {
  916.                getMenuAt(openMenuIndex).hide();
  917.             }
  918.             param1.stopPropagation();
  919.          }
  920.       }
  921.       
  922.       [Bindable("labelFieldChanged")]
  923.       public function get labelField() : String
  924.       {
  925.          return _labelField;
  926.       }
  927.       
  928.       public function set selectedIndex(param1:int) : void
  929.       {
  930.          openMenuIndex = param1;
  931.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  932.       }
  933.       
  934.       private function mouseOverHandler(param1:MouseEvent) : void
  935.       {
  936.          var _loc6_:MenuEvent = null;
  937.          var _loc7_:Number = NaN;
  938.          var _loc8_:ICollectionView = null;
  939.          var _loc9_:IMenuBarItemRenderer = null;
  940.          var _loc10_:Menu = null;
  941.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  942.          var _loc3_:int = _loc2_.menuBarItemIndex;
  943.          var _loc4_:Boolean = false;
  944.          var _loc5_:Menu = getMenuAt(_loc3_);
  945.          if(_loc2_.enabled)
  946.          {
  947.             if(openMenuIndex != -1 || inKeyDown)
  948.             {
  949.                _loc7_ = openMenuIndex;
  950.                if(_loc7_ != _loc3_)
  951.                {
  952.                   isDown = false;
  953.                   if(_loc7_ != -1)
  954.                   {
  955.                      _loc9_ = menuBarItems[_loc7_];
  956.                      _loc9_.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
  957.                      _loc9_.menuBarItemState = "itemUpSkin";
  958.                      _loc6_ = new MenuEvent(MenuEvent.ITEM_ROLL_OUT);
  959.                      _loc6_.menuBar = this;
  960.                      _loc6_.index = _loc7_;
  961.                      _loc6_.label = itemToLabel(_loc9_.data);
  962.                      _loc6_.item = _loc9_.data;
  963.                      _loc6_.itemRenderer = _loc9_;
  964.                      dispatchEvent(_loc6_);
  965.                   }
  966.                   _loc2_.menuBarItemState = "itemDownSkin";
  967.                   _loc8_ = ICollectionView(_loc5_.dataProvider);
  968.                   if(_loc5_.dataDescriptor.isBranch(_loc2_.data,_loc2_.data) && _loc5_.dataDescriptor.hasChildren(_loc2_.data,_loc2_.data))
  969.                   {
  970.                      showMenu(_loc3_);
  971.                   }
  972.                   else if(_loc5_)
  973.                   {
  974.                      selectedIndex = _loc3_;
  975.                      _loc6_ = new MenuEvent(MenuEvent.MENU_SHOW);
  976.                      _loc6_.menuBar = this;
  977.                      _loc6_.menu = _loc5_;
  978.                      dispatchEvent(_loc6_);
  979.                      _loc2_.menuBarItemState = "itemOverSkin";
  980.                   }
  981.                   isDown = true;
  982.                   if(_loc5_.dataDescriptor.getType(_loc2_.data) != "separator")
  983.                   {
  984.                      _loc4_ = true;
  985.                      _loc6_ = new MenuEvent(MenuEvent.CHANGE);
  986.                      _loc6_.index = _loc3_;
  987.                      _loc6_.menuBar = this;
  988.                      _loc6_.label = itemToLabel(_loc2_.data);
  989.                      _loc6_.item = _loc2_.data;
  990.                      _loc6_.itemRenderer = _loc2_;
  991.                      dispatchEvent(_loc6_);
  992.                   }
  993.                }
  994.                else
  995.                {
  996.                   _loc10_ = getMenuAt(_loc3_);
  997.                   _loc10_.mx_internal::deleteDependentSubMenus();
  998.                   _loc10_.setFocus();
  999.                }
  1000.             }
  1001.             else
  1002.             {
  1003.                _loc2_.menuBarItemState = "itemOverSkin";
  1004.                isDown = false;
  1005.                if(_loc5_.dataDescriptor.getType(_loc2_.data) != "separator")
  1006.                {
  1007.                   _loc4_ = true;
  1008.                }
  1009.             }
  1010.             inKeyDown = false;
  1011.             if(_loc4_)
  1012.             {
  1013.                _loc6_ = new MenuEvent(MenuEvent.ITEM_ROLL_OVER);
  1014.                _loc6_.index = _loc3_;
  1015.                _loc6_.menuBar = this;
  1016.                _loc6_.label = itemToLabel(_loc2_.data);
  1017.                _loc6_.item = _loc2_.data;
  1018.                _loc6_.itemRenderer = _loc2_;
  1019.                dispatchEvent(_loc6_);
  1020.             }
  1021.          }
  1022.       }
  1023.       
  1024.       public function set dataDescriptor(param1:IMenuDataDescriptor) : void
  1025.       {
  1026.          mx_internal::_dataDescriptor = param1;
  1027.          menus = [];
  1028.       }
  1029.       
  1030.       private function insertMenuBarItem(param1:int, param2:Object) : void
  1031.       {
  1032.          if(dataProviderChanged)
  1033.          {
  1034.             commitProperties();
  1035.             return;
  1036.          }
  1037.          var _loc3_:IMenuBarItemRenderer = menuBarItemRenderer.newInstance();
  1038.          _loc3_.styleName = new StyleProxy(this,menuBarItemStyleFilters);
  1039.          _loc3_.visible = false;
  1040.          _loc3_.enabled = enabled && mx_internal::_dataDescriptor.isEnabled(param2) != false;
  1041.          _loc3_.data = param2;
  1042.          _loc3_.menuBar = this;
  1043.          _loc3_.menuBarItemIndex = param1;
  1044.          addChild(DisplayObject(_loc3_));
  1045.          menuBarItems.splice(param1,0,_loc3_);
  1046.          invalidateSize();
  1047.          invalidateDisplayList();
  1048.          _loc3_.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
  1049.          _loc3_.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  1050.          _loc3_.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
  1051.          _loc3_.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
  1052.       }
  1053.       
  1054.       public function set dataProvider(param1:Object) : void
  1055.       {
  1056.          var _loc3_:XMLList = null;
  1057.          var _loc4_:Array = null;
  1058.          if(mx_internal::_rootModel)
  1059.          {
  1060.             mx_internal::_rootModel.removeEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler);
  1061.          }
  1062.          if(typeof param1 == "string")
  1063.          {
  1064.             param1 = new XML(param1);
  1065.          }
  1066.          else if(param1 is XMLNode)
  1067.          {
  1068.             param1 = new XML(XMLNode(param1).toString());
  1069.          }
  1070.          else if(param1 is XMLList)
  1071.          {
  1072.             param1 = new XMLListCollection(param1 as XMLList);
  1073.          }
  1074.          if(param1 is XML)
  1075.          {
  1076.             mx_internal::_hasRoot = true;
  1077.             _loc3_ = new XMLList();
  1078.             _loc3_ += param1;
  1079.             mx_internal::_rootModel = new XMLListCollection(_loc3_);
  1080.          }
  1081.          else if(param1 is ICollectionView)
  1082.          {
  1083.             mx_internal::_rootModel = ICollectionView(param1);
  1084.             if(mx_internal::_rootModel.length == 1)
  1085.             {
  1086.                mx_internal::_hasRoot = true;
  1087.             }
  1088.          }
  1089.          else if(param1 is Array)
  1090.          {
  1091.             mx_internal::_rootModel = new ArrayCollection(param1 as Array);
  1092.          }
  1093.          else if(param1 is Object)
  1094.          {
  1095.             mx_internal::_hasRoot = true;
  1096.             _loc4_ = [];
  1097.             _loc4_.push(param1);
  1098.             mx_internal::_rootModel = new ArrayCollection(_loc4_);
  1099.          }
  1100.          else
  1101.          {
  1102.             mx_internal::_rootModel = new ArrayCollection();
  1103.          }
  1104.          mx_internal::_rootModel.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,0,true);
  1105.          dataProviderChanged = true;
  1106.          invalidateProperties();
  1107.          var _loc2_:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
  1108.          _loc2_.kind = CollectionEventKind.RESET;
  1109.          collectionChangeHandler(_loc2_);
  1110.          dispatchEvent(_loc2_);
  1111.       }
  1112.       
  1113.       [Bindable("valueCommit")]
  1114.       public function get selectedIndex() : int
  1115.       {
  1116.          return openMenuIndex;
  1117.       }
  1118.       
  1119.       override protected function focusInHandler(param1:FocusEvent) : void
  1120.       {
  1121.          super.focusInHandler(param1);
  1122.       }
  1123.       
  1124.       private function eventHandler(param1:Event) : void
  1125.       {
  1126.          var _loc2_:String = null;
  1127.          if(param1 is MenuEvent)
  1128.          {
  1129.             _loc2_ = param1.type;
  1130.             if(param1.type == MenuEvent.MENU_HIDE && MenuEvent(param1).menu == menus[openMenuIndex])
  1131.             {
  1132.                menuBarItems[openMenuIndex].menuBarItemState = "itemUpSkin";
  1133.                openMenuIndex = -1;
  1134.                dispatchEvent(param1 as MenuEvent);
  1135.             }
  1136.             else
  1137.             {
  1138.                dispatchEvent(param1);
  1139.             }
  1140.          }
  1141.       }
  1142.       
  1143.       public function set showRoot(param1:Boolean) : void
  1144.       {
  1145.          if(mx_internal::_showRoot != param1)
  1146.          {
  1147.             mx_internal::showRootChanged = true;
  1148.             mx_internal::_showRoot = param1;
  1149.             invalidateProperties();
  1150.          }
  1151.       }
  1152.    }
  1153. }
  1154.  
  1155.